package org.linlinjava.litemall.db.service;

import org.linlinjava.litemall.db.dao.LitemallMessageMapper;
import org.linlinjava.litemall.db.domain.LitemallMessage;
import org.linlinjava.litemall.db.domainVo.MessageVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class LitemallMessageService {
    @Autowired
    LitemallMessageMapper messageMapper;

    /**
     * 查詢消息列表
     *
     * @param userId
     * @return
     */
    public List<MessageVo> findMessageByUserId(Integer userId) {
        List<MessageVo> message = messageMapper.selectByUserId(userId);
        return message;
    }

    /**
     * 修改状态
     *
     * @param message
     * @return
     */
    public int updateMessage(LitemallMessage message) {
        return messageMapper.updateByCommitId(message);
    }

    /**
     * 插入注册消息
     * @param id
     */
    public void insertMessage(Integer id,Integer userId,int userLevel,Integer state,String content) {
        LitemallMessage message = new LitemallMessage();
        message.setCommitid(id);
        message.setUserid(userId);
        message.setStar(userLevel+1);
        message.setContent(content);
        message.setState(state);
        message.setCreatetime(LocalDateTime.now());
        messageMapper.insert(message);
    }

    public List<MessageVo> selectByCommitId(Integer commitId) {
        List<MessageVo> message = messageMapper.selectByCommitId(commitId);
        return message;
    }

    public List<LitemallMessage> findMessageByStatus() {
        return messageMapper.findMessageByStatus();
    }

    public void deleteMessageByUserId(Integer userid) {
        messageMapper.deleteMessageByUserId(userid);
    }
}
